dofile "game\\Input.lua"
dofile "game\\Ground.lua"

local system = ParticleSystem()
local camera = Camera()

local currentGround = 1

local mesh

function createEmitter()
	emitter = ParticleEmitter()
	emitter.size = 0.5
	emitter.maxParticles = 1400
	emitter.numToEmit = 5
	emitter.emitIntervall = 0.05
	emitter.lifeCycle = 2
	emitter.velocityAmount = 1
	emitter.airResistance = false
	emitter.velocity = Vector3(0, 15, 0)
	emitter.gravity = Vector3(0, -15, 0)
	emitter.position = Vector3(0, 0, 10)
	emitter.texture = "game\\images\\particle.png"
	emitter.minRandomSpread = -1
	emitter.maxRandomSpread =  1
	emitter:initialize()
	
	emitter4 = ParticleEmitter()
	emitter4.size = 0.5
	emitter4.maxParticles = 1400
	emitter4.numToEmit = 5
	emitter4.emitIntervall = 0.05
	emitter4.lifeCycle = 2
	emitter4.velocityAmount = 1
	emitter4.airResistance = false
	emitter4.velocity = Vector3(0, 15, 0)
	emitter4.gravity = Vector3(0, -15, 0)
	emitter4.position = Vector3(0, 0, 10)
	emitter4.texture = "game\\images\\particle2.png"
	emitter4.minRandomSpread = -3
	emitter4.maxRandomSpread =  2
	emitter4:initialize()
	
	emitter2 = ParticleEmitter()
	emitter2.maxParticles = 1400
	emitter2.size = 2
	emitter2.numToEmit = 50
	emitter2.emitIntervall = 2
	emitter2.lifeCycle = 2
	emitter2.velocityAmount = 1
	emitter2.airResistance = false
	emitter2.velocity = Vector3(0, 15, 0)
	emitter2.gravity = Vector3(0, -15, 0)
	emitter2.position = Vector3(5, 0, 10)
	emitter2.color = Color(1, 1, 1, 1)
	emitter2.texture = "game\\images\\particle3.png"
	emitter2.maxRandomSpread =  22
	emitter2:initialize()
	
	emitter3 = ParticleEmitter()
	emitter3.maxParticles = 15
	emitter3.numToEmit = 1
	emitter3.emitIntervall = .5
	emitter3.lifeCycle = 4
	emitter3.airResistance = true
	emitter3.velocity = Vector3(0, 2, -8)
	emitter3.gravity = Vector3(0, -5, 0)
	emitter3.position = Vector3(-5, 10, 15)
	emitter3.color = Color(1, 1, 1, 1)
	emitter3.texture = "game\\images\\particle4.png"
	emitter3:initialize()
	
	system:addEmitter(emitter)
	system:addEmitter(emitter4)
	system:addEmitter(emitter2)
	system:addEmitter(emitter3)
end

function updateMesh(elapsedTime)
	local moveSpeed = 2
	local move = moveSpeed*elapsedTime

	if(game:keyPressed("Z")) then
		mesh:move(Vector3(0, 0, move))
	elseif(game:keyPressed("H")) then
		mesh:move(Vector3(0, 0, -move))
	end

	if(game:keyPressed("J")) then
		mesh:move(Vector3(move, 0, 0))
	elseif(game:keyPressed("G")) then
		mesh:move(Vector3(-move, 0, 0))
	end
end


function onDraw(elapsedTime)
	handleInput(elapsedTime, game, camera)
	updateMesh(elapsedTime)
	mesh:render()
	
	renderGround()
	system:update(elapsedTime)
end


function main()
	game:showConsole()
	print(cmdline)
	game:initialize(1920, 1080, "Test")

	createEmitter()

	mesh = DynamicMesh(Vector3(10, 5, 5), Vector3(1, 1, 1))
	mesh:fromObjFile("game\\testmesh.obj", 1)
	mesh.texture = "game\\images\\ground_plate01.png"

	createGround(10, 10)

	camera:rotate(0, 90)
	camera:move(0, 50, 0)

	game:setOnDrawEvent(onDraw)
	game:start()
end

print("Hey")